package com.news;

import android.app.Activity;
import android.util.Log;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.widget.Toast;

class Gestures extends SimpleOnGestureListener {
  
  private Activity a = null;
  
  final int horizontalRange = 10;
  
  final int verticalRange = 50;
  
  final int GESTURE_LEFT = 1;
  
  final int GESTURE_RIGHT = 2;
  
  final int GESTURE_INVALID = 0;

  public Gestures(Activity activity) {
    a = activity;
  }

  public Gestures() {

  }

  @Override
  public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
      float velocityY) {
    Toast.makeText(a.getApplicationContext(), "FLING", Toast.LENGTH_SHORT).show();
    return false;
  }

  @Override
  public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
      float distanceY) {
    Log.d("action", e1.getAction()+"");
    if (distanceY<horizontalRange && distanceX>verticalRange) {
      android.webkit.WebView webView = (android.webkit.WebView)a.getWindow().getDecorView().findViewById(R.id.Webview);
      webView.goBack();
      //Toast.makeText(a.getApplicationContext(), "Left" + distanceX, Toast.LENGTH_SHORT).show();
    }
    else if(distanceY<horizontalRange && distanceX < -verticalRange) {
      android.webkit.WebView webView = (android.webkit.WebView)a.getWindow().getDecorView().findViewById(R.id.Webview);
      webView.goForward();
    }
    return false;
  }

  @Override
  public boolean onDown(MotionEvent me) {
    return true;
  }
}